﻿var participants = new Array();
var questionID = -2;
var questionType = "singleResponse";
var responseHandler = "gridResponseHandler";

function gridResponseHandler(deviceID, response) {
    $.ajax({
        type: 'POST',
        url: "/Respond/AddGridResponse",
        data: { deviceID: deviceID, pollID: $('#pollID').val() }
    });
}

function optionResponseHandler(deviceID, response) {
    if (response.length > 1) {
        response = response.trim();
        for (var i = 0; i < response.length; i++) {
            if (!isNaN(parseFloat(response[i])) && isFinite(response[i])) {
                optionResponseHandler(deviceID, response[i]);
            }
        }
    }
    else {
        if (!participants[deviceID]) {
            participants[deviceID] = 1;
        }
        if (response != "?") {
            $.ajax({
                type: 'POST',
                url: "/Respond/SaveKeypadOptionResponse",
                data: { deviceID: deviceID, response: response, rank: participants[deviceID], questionID: questionID }
            });
            participants[deviceID]++;
        }
    }
}

function shortResponseHandler(deviceID, response) {
    if (!isNaN(response)) {
        $.ajax({
            type: 'POST',
            url: "/Respond/SaveKeypadNumericResponse",
            data: { deviceID: deviceID, response: response, questionID: questionID }
        });
    }
}

